package bank.mvc;


import framework.mvc.AFincoView;

import java.util.HashMap;
import java.util.Map;

public class AddPersonalDialog extends javax.swing.JDialog {

    private static final long serialVersionUID = 1L;

    private AFincoView parentframe;
    private boolean created = false;
    private Map<String, String> map;

    public AddPersonalDialog(AFincoView parent) {
        super(parent);
        parentframe = parent;

        // This code is automatically generated by Visual Cafe when you add
        // components to the visual environment. It instantiates and initializes
        // the components. To modify the code, only use code syntax that matches
        // what Visual Cafe can generate, or Visual Cafe may be unable to back
        // parse your Java file into its visual environment.
        // {{INIT_CONTROLS
        setTitle("Add personal account");
        setModal(true);
        getContentPane().setLayout(null);
        setSize(283, 303);
        setVisible(false);
        JRadioButton_Chk.setText("Checkings");
        JRadioButton_Chk.setActionCommand("Checkings");
        getContentPane().add(JRadioButton_Chk);
        JRadioButton_Chk.setBounds(36, 0, 84, 24);
        JRadioButton_Sav.setText("Savings");
        JRadioButton_Sav.setActionCommand("Savings");
        getContentPane().add(JRadioButton_Sav);
        JRadioButton_Sav.setBounds(36, 24, 84, 24);
        JLabel1.setText("Name");
        getContentPane().add(JLabel1);
        JLabel1.setForeground(java.awt.Color.black);
        JLabel1.setBounds(12, 84, 48, 24);
        JLabel2.setText("Street");
        getContentPane().add(JLabel2);
        JLabel2.setForeground(java.awt.Color.black);
        JLabel2.setBounds(12, 108, 48, 24);
        JLabel3.setText("City");
        getContentPane().add(JLabel3);
        JLabel3.setForeground(java.awt.Color.black);
        JLabel3.setBounds(12, 132, 48, 24);
        JLabel4.setText("State");
        getContentPane().add(JLabel4);
        JLabel4.setForeground(java.awt.Color.black);
        JLabel4.setBounds(12, 156, 48, 24);
        JLabel5.setText("Zip");
        getContentPane().add(JLabel5);
        JLabel5.setForeground(java.awt.Color.black);
        JLabel5.setBounds(12, 180, 48, 24);
        JLabel6.setText("Birthdate");
        getContentPane().add(JLabel6);
        JLabel6.setForeground(java.awt.Color.black);
        JLabel6.setBounds(12, 204, 96, 24);
        JLabel7.setText("Email");
        getContentPane().add(JLabel7);
        JLabel7.setForeground(java.awt.Color.black);
        JLabel7.setBounds(12, 228, 48, 24);
        getContentPane().add(JTextField_NAME);
        JTextField_NAME.setBounds(84, 84, 156, 20);
        getContentPane().add(JTextField_CT);
        JTextField_CT.setBounds(84, 132, 156, 20);
        getContentPane().add(JTextField_ST);
        JTextField_ST.setBounds(84, 156, 156, 20);
        getContentPane().add(JTextField_STR);
        JTextField_STR.setBounds(84, 108, 156, 20);
        getContentPane().add(JTextField_ZIP);
        JTextField_ZIP.setBounds(84, 180, 156, 20);
        getContentPane().add(JTextField_BD);
        JTextField_BD.setBounds(84, 204, 156, 20);
        getContentPane().add(JTextField_EM);
        JTextField_EM.setBounds(84, 228, 156, 20);
        JButton_OK.setText("OK");
        JButton_OK.setActionCommand("OK");
        getContentPane().add(JButton_OK);
        JButton_OK.setBounds(48, 264, 84, 24);
        JButton_Cancel.setText("Cancel");
        JButton_Cancel.setActionCommand("Cancel");
        getContentPane().add(JButton_Cancel);
        JButton_Cancel.setBounds(156, 264, 84, 24);
        getContentPane().add(JTextField_ACNR);
        JTextField_ACNR.setBounds(84, 60, 156, 20);
        JLabel8.setText("Acc Nr");
        getContentPane().add(JLabel8);
        JLabel8.setForeground(java.awt.Color.black);
        JLabel8.setBounds(12, 60, 48, 24);
        // }}

        // {{REGISTER_LISTENERS
        SymMouse aSymMouse = new SymMouse();
        JRadioButton_Chk.addMouseListener(aSymMouse);
        JRadioButton_Sav.addMouseListener(aSymMouse);
        SymAction lSymAction = new SymAction();
        JButton_OK.addActionListener(lSymAction);
        JButton_Cancel.addActionListener(lSymAction);
        // }}
    }

    // {{DECLARE_CONTROLS
    /**
     * @uml.property name="jRadioButton_Chk"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JRadioButton JRadioButton_Chk = new javax.swing.JRadioButton();
    /**
     * @uml.property name="jRadioButton_Sav"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JRadioButton JRadioButton_Sav = new javax.swing.JRadioButton();
    /**
     * @uml.property name="jLabel1"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JLabel JLabel1 = new javax.swing.JLabel();
    /**
     * @uml.property name="jLabel2"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JLabel JLabel2 = new javax.swing.JLabel();
    /**
     * @uml.property name="jLabel3"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JLabel JLabel3 = new javax.swing.JLabel();
    /**
     * @uml.property name="jLabel4"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JLabel JLabel4 = new javax.swing.JLabel();
    /**
     * @uml.property name="jLabel5"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JLabel JLabel5 = new javax.swing.JLabel();
    /**
     * @uml.property name="jLabel6"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JLabel JLabel6 = new javax.swing.JLabel();
    /**
     * @uml.property name="jLabel7"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JLabel JLabel7 = new javax.swing.JLabel();
    /**
     * @uml.property name="jTextField_NAME"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JTextField JTextField_NAME = new javax.swing.JTextField();
    /**
     * @uml.property name="jTextField_CT"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JTextField JTextField_CT = new javax.swing.JTextField();
    /**
     * @uml.property name="jTextField_ST"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JTextField JTextField_ST = new javax.swing.JTextField();
    /**
     * @uml.property name="jTextField_STR"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JTextField JTextField_STR = new javax.swing.JTextField();
    /**
     * @uml.property name="jTextField_ZIP"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JTextField JTextField_ZIP = new javax.swing.JTextField();
    /**
     * @uml.property name="jTextField_BD"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JTextField JTextField_BD = new javax.swing.JTextField();
    /**
     * @uml.property name="jTextField_EM"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JTextField JTextField_EM = new javax.swing.JTextField();
    /**
     * @uml.property name="jButton_OK"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JButton JButton_OK = new javax.swing.JButton();
    /**
     * @uml.property name="jButton_Cancel"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JButton JButton_Cancel = new javax.swing.JButton();
    /**
     * @uml.property name="jTextField_ACNR"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JTextField JTextField_ACNR = new javax.swing.JTextField();
    /**
     * @uml.property name="jLabel8"
     * @uml.associationEnd multiplicity="(1 1)"
     */
    javax.swing.JLabel JLabel8 = new javax.swing.JLabel();

    // }}

    class SymMouse extends java.awt.event.MouseAdapter {
        public void mouseClicked(java.awt.event.MouseEvent event) {
            Object object = event.getSource();
            if (object == JRadioButton_Chk)
                JRadioButtonChk_mouseClicked(event);
            else if (object == JRadioButton_Sav)
                JRadioButtonSav_mouseClicked(event);
        }
    }

    void JRadioButtonChk_mouseClicked(java.awt.event.MouseEvent event) {
        // When Checking radio is clicked make this radio on
        // and make Saving account radio off
        JRadioButton_Chk.setSelected(true);
        JRadioButton_Sav.setSelected(false);
    }

    void JRadioButtonSav_mouseClicked(java.awt.event.MouseEvent event) {
        // When Saving radio is clicked make this radio on
        // and make Checking account radio off
        JRadioButton_Chk.setSelected(false);
        JRadioButton_Sav.setSelected(true);

    }

    class SymAction implements java.awt.event.ActionListener {
        public void actionPerformed(java.awt.event.ActionEvent event) {
            Object object = event.getSource();
            if (object == JButton_OK)
                JButtonOK_actionPerformed(event);
            else if (object == JButton_Cancel)
                JButtonCalcel_actionPerformed(event);
        }
    }

    void JButtonCalcel_actionPerformed(java.awt.event.ActionEvent event) {
        // make this frame invisible if Cancel button is clicked
        dispose();
    }

    void JButtonOK_actionPerformed(java.awt.event.ActionEvent event) {
        String type = getRadioType();
        map = new HashMap<String, String>();

        map.put("type", type);
        map.put("name", JTextField_NAME.getText());
        map.put("street", JTextField_STR.getText());
        map.put("city", JTextField_CT.getText());
        map.put("zip", JTextField_ZIP.getText());
        map.put("email", JTextField_EM.getText());
        map.put("state", JTextField_ST.getText());
        map.put("ccNumber", JTextField_ACNR.getText());
        map.put("dob", JTextField_BD.getText());
        map.put("p/c", "P");
        created = true;
        dispose();
    }

    /*private ICustomer AddAndGetCustomer(Map<String, String> map) {
        if (!Finco.getInstance().isExist(map.get("name"))) {
            ICustomer customer = CustomerFactory.createCustomer(getArrayMap(map));
            Finco.getInstance().addCustomer(customer);
            return customer;
        } else
            return Finco.getInstance().getCustomerByName(map.get("name"));
    }

    private Object[] getArrayMap(Map<String, String> map) {
        Object[] tmp = new Object[8];
        tmp[0] = map.get("p/c");
        tmp[1] = map.get("name");
        tmp[2] = map.get("street");
        tmp[3] = map.get("city");
        tmp[4] = map.get("zip");
        tmp[5] = map.get("email");
        tmp[6] = map.get("state");
        tmp[7] = map.get("dob");
        return tmp;
    }*/

    public boolean isCreated() {
        return created;
    }

    public Map<String, String> getCustomerMap() {
        return map;
    }

    private String getRadioType() {
        if (JRadioButton_Chk.isSelected())
            return "Ch";
        return "S";
    }
}